home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / ultqsrc.zip / TRIGGERS.QC < prev    next >
Text File  |  1996-09-23  |  16KB  |  670 lines

  1.  
  2. entity stemp, otemp, s, old;
  3.  
  4.  
  5. void() trigger_reactivate =
  6. {
  7.     self.solid = SOLID_TRIGGER;
  8. };
  9.  
  10. //=============================================================================
  11.  
  12. float    SPAWNFLAG_NOMESSAGE = 1;
  13. float    SPAWNFLAG_NOTOUCH = 1;
  14.  
  15. // the wait time has passed, so set back up for another activation
  16. void() multi_wait =
  17. {
  18.     if (self.max_health)
  19.     {
  20.         self.health = self.max_health;
  21.         self.takedamage = DAMAGE_YES;
  22.         self.solid = SOLID_BBOX;
  23.     }
  24. };
  25.  
  26.  
  27. // the trigger was just touched/killed/used
  28. // self.enemy should be set to the activator so it can be held through a delay
  29. // so wait for the delay time before firing
  30. void() multi_trigger =
  31. {
  32. local string printnum;
  33.     if (self.nextthink > time)
  34.     {
  35.         return;        // allready been triggered
  36.     }
  37.  
  38.     if (self.classname == "trigger_secret")
  39.     {
  40.         if (self.enemy.classname != "player")
  41.             return;
  42.         found_secrets = found_secrets + 1;
  43.         WriteByte (MSG_ALL, SVC_FOUNDSECRET);
  44.                 self.enemy.exp = self.enemy.exp + 500;
  45.                 sprint(self.enemy,"Experience points: ");
  46.                 printnum=ftos(self.enemy.exp);
  47.                 sprint(self.enemy,printnum);
  48.                 sprint(self.enemy,"\n");
  49.     }
  50.  
  51.     if (self.noise)
  52.         sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  53.  
  54. // don't trigger again until reset
  55.     self.takedamage = DAMAGE_NO;
  56.  
  57.     activator = self.enemy;
  58.     
  59.     SUB_UseTargets();
  60.  
  61.     if (self.wait > 0)    
  62.     {
  63.         self.think = multi_wait;
  64.         self.nextthink = time + self.wait;
  65.     }
  66.     else
  67.     {    // we can't just remove (self) here, because this is a touch function
  68.         // called wheil C code is looping through area links...
  69.         self.touch = SUB_Null;
  70.         self.nextthink = time + 0.1;
  71.         self.think = SUB_Remove;
  72.     }
  73. };
  74.  
  75. void() multi_killed =
  76. {
  77.     self.enemy = damage_attacker;
  78.     multi_trigger();
  79. };
  80.  
  81. void() multi_use =
  82. {
  83.     self.enemy = activator;
  84.     multi_trigger();
  85. };
  86.  
  87. void() multi_touch =
  88. {
  89.     if (other.classname != "player")
  90.         return;
  91.     
  92. // if the trigger has an angles field, check player's facing direction
  93.     if (self.movedir != '0 0 0')
  94.     {
  95.         makevectors (other.angles);
  96.         if (v_forward * self.movedir < 0)
  97.             return;        // not facing the right way
  98.     }
  99.     
  100.     self.enemy = other;
  101.     multi_trigger ();
  102. };
  103.  
  104. /*QUAKED trigger_multiple (.5 .5 .5) ? notouch
  105. Variable sized repeatable trigger.  Must be targeted at one or more entities.  If "health" is set, the trigger must be killed to activate each time.
  106. If "delay" is set, the trigger waits some time after activating before firing.
  107. "wait" : Seconds between triggerings. (.2 default)
  108. If notouch is set, the trigger is only fired by other entities, not by touching.
  109. NOTOUCH has been obsoleted by trigger_relay!
  110. sounds
  111. 1)    secret
  112. 2)    beep beep
  113. 3)    large switch
  114. 4)
  115. set "message" to text string
  116. */
  117. void() trigger_multiple =
  118. {
  119.     if (self.sounds == 1)
  120.     {
  121.         precache_sound ("misc/secret.wav");
  122.         self.noise = "misc/secret.wav";
  123.     }
  124.     else if (self.sounds == 2)
  125.     {
  126.         precache_sound ("misc/talk.wav");
  127.         self.noise = "misc/talk.wav";
  128.     }
  129.     else if (self.sounds == 3)
  130.     {
  131.         precache_sound ("misc/trigger1.wav");
  132.         self.noise = "misc/trigger1.wav";
  133.     }
  134.     
  135.     if (!self.wait)
  136.         self.wait = 0.2;
  137.     self.use = multi_use;
  138.  
  139.     InitTrigger ();
  140.  
  141.     if (self.health)
  142.     {
  143.         if (self.spawnflags & SPAWNFLAG_NOTOUCH)
  144.             objerror ("health and notouch don't make sense\n");
  145.         self.max_health = self.health;
  146.         self.th_die = multi_killed;
  147.         self.takedamage = DAMAGE_YES;
  148.         self.solid = SOLID_BBOX;
  149.         setorigin (self, self.origin);    // make sure it links into the world
  150.     }
  151.     else
  152.     {
  153.         if ( !(self.spawnflags & SPAWNFLAG_NOTOUCH) )
  154.         {
  155.             self.touch = multi_touch;
  156.         }
  157.     }
  158. };
  159.  
  160.  
  161. /*QUAKED trigger_once (.5 .5 .5) ? notouch
  162. Variable sized trigger. Triggers once, then removes itself.  You must set the key "target" to the name of another object in the level that has a matching
  163. "targetname".  If "health" is set, the trigger must be killed to activate.
  164. If notouch is set, the trigger is only fired by other entities, not by touching.
  165. if "killtarget" is set, any objects that have a matching "target" will be removed when the trigger is fired.
  166. if "angle" is set, the trigger will only fire when someone is facing the direction of the angle.  Use "360" for an angle of 0.
  167. sounds
  168. 1)    secret
  169. 2)    beep beep
  170. 3)    large switch
  171. 4)
  172. set "message" to text string
  173. */
  174. void() trigger_once =
  175. {
  176.     self.wait = -1;
  177.     trigger_multiple();
  178. };
  179.  
  180. //=============================================================================
  181.  
  182. /*QUAKED trigger_relay (.5 .5 .5) (-8 -8 -8) (8 8 8)
  183. This fixed size trigger cannot be touched, it can only be fired by other events.  It can contain killtargets, targets, delays, and messages.
  184. */
  185. void() trigger_relay =
  186. {
  187.     self.use = SUB_UseTargets;
  188. };
  189.  
  190.  
  191. //=============================================================================
  192.  
  193. /*QUAKED trigger_secret (.5 .5 .5) ?
  194. secret counter trigger
  195. sounds
  196. 1)    secret
  197. 2)    beep beep
  198. 3)
  199. 4)
  200. set "message" to text string
  201. */
  202. void() trigger_secret =
  203. {
  204.     total_secrets = total_secrets + 1;
  205.     self.wait = -1;
  206.     if (!self.message)
  207.         self.message = "You found a secret area!";
  208.     if (!self.sounds)
  209.         self.sounds = 1;
  210.     
  211.     if (self.sounds == 1)
  212.     {
  213.         precache_sound ("misc/secret.wav");
  214.         self.noise = "misc/secret.wav";
  215.     }
  216.     else if (self.sounds == 2)
  217.     {
  218.         precache_sound ("misc/talk.wav");
  219.         self.noise = "misc/talk.wav";
  220.     }
  221.  
  222.     trigger_multiple ();
  223. };
  224.  
  225. //=============================================================================
  226.  
  227.  
  228. void() counter_use =
  229. {
  230.     local string junk;
  231.  
  232.     self.count = self.count - 1;
  233.     if (self.count < 0)
  234.         return;
  235.     
  236.     if (self.count != 0)
  237.     {
  238.         if (activator.classname == "player"
  239.         && (self.spawnflags & SPAWNFLAG_NOMESSAGE) == 0)
  240.         {
  241.             if (self.count >= 4)
  242.                 centerprint (activator, "There are more to go...");
  243.             else if (self.count == 3)
  244.                 centerprint (activator, "Only 3 more to go...");
  245.             else if (self.count == 2)
  246.                 centerprint (activator, "Only 2 more to go...");
  247.             else
  248.                 centerprint (activator, "Only 1 more to go...");
  249.         }
  250.         return;
  251.     }
  252.     
  253.     if (activator.classname == "player"
  254.     && (self.spawnflags & SPAWNFLAG_NOMESSAGE) == 0)
  255.         centerprint(activator, "Sequence completed!");
  256.     self.enemy = activator;
  257.     multi_trigger ();
  258. };
  259.  
  260. /*QUAKED trigger_counter (.5 .5 .5) ? nomessage
  261. Acts as an intermediary for an action that takes multiple inputs.
  262.  
  263. If nomessage is not set, t will print "1 more.. " etc when triggered and "sequence complete" when finished.
  264.  
  265. After the counter has been triggered "count" times (default 2), it will fire all of it's targets and remove itself.
  266. */
  267. void() trigger_counter =
  268. {
  269.     self.wait = -1;
  270.     if (!self.count)
  271.         self.count = 2;
  272.  
  273.     self.use = counter_use;
  274. };
  275.  
  276.  
  277. /*
  278. ==============================================================================
  279.  
  280. TELEPORT TRIGGERS
  281.  
  282. ==============================================================================
  283. */
  284.  
  285. float    PLAYER_ONLY    = 1;
  286. float    SILENT = 2;
  287.  
  288. void() play_teleport =
  289. {
  290.     local    float v;
  291.     local    string tmpstr;
  292.  
  293.     v = random() * 5;
  294.     if (v < 1)
  295.         tmpstr = "misc/r_tele1.wav";
  296.     else if (v < 2)
  297.         tmpstr = "misc/r_tele2.wav";
  298.     else if (v < 3)
  299.         tmpstr = "misc/r_tele3.wav";
  300.     else if (v < 4)
  301.         tmpstr = "misc/r_tele4.wav";
  302.     else
  303.         tmpstr = "misc/r_tele5.wav";
  304.  
  305.     sound (self, CHAN_VOICE, tmpstr, 1, ATTN_NORM);
  306.     remove (self);
  307. };
  308.  
  309. void(vector org) spawn_tfog =
  310. {
  311.     s = spawn ();
  312.     s.origin = org;
  313.     s.nextthink = time + 0.2;
  314.     s.think = play_teleport;
  315.  
  316.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  317.     WriteByte (MSG_BROADCAST, TE_TELEPORT);
  318.     WriteCoord (MSG_BROADCAST, org_x);
  319.     WriteCoord (MSG_BROADCAST, org_y);
  320.     WriteCoord (MSG_BROADCAST, org_z);
  321. };
  322.  
  323.  
  324. void() tdeath_touch =
  325. {
  326.     if (other == self.owner)
  327.         return;
  328.  
  329. // frag anyone who teleports in on top of an invincible player
  330.     if (other.classname == "player")
  331.     {
  332.         if (other.invincible_finished > time)
  333.             self.classname = "teledeath2";
  334.         if (self.owner.classname != "player")
  335.         {    // other monsters explode themselves
  336.             T_Damage (self.owner, self, self, 50000);
  337.             return;
  338.         }
  339.         
  340.     }
  341.  
  342.     if (other.health)
  343.     {
  344.         T_Damage (other, self, self, 50000);
  345.     }
  346. };
  347.  
  348.  
  349. void(vector org, entity death_owner) spawn_tdeath =
  350. {
  351. local entity    death;
  352.  
  353.     death = spawn();
  354.     death.classname = "teledeath";
  355.     death.movetype = MOVETYPE_NONE;
  356.     death.solid = SOLID_TRIGGER;
  357.     death.angles = '0 0 0';
  358.     setsize (death, death_owner.mins - '1 1 1', death_owner.maxs + '1 1 1');
  359.     setorigin (death, org);
  360.     death.touch = tdeath_touch;
  361.     death.nextthink = time + 0.2;
  362.     death.think = SUB_Remove;
  363.     death.owner = death_owner;
  364.     
  365.     force_retouch = 2;        // make sure even still objects get hit
  366. };
  367.  
  368. void() teleport_touch =
  369. {
  370.  local entity    t;
  371.  local vector    org;
  372.  
  373.        if (self.targetname)
  374.        {
  375.                if (self.nextthink < time)
  376.                {
  377.                        return;         // not fired yet
  378.                }
  379.        }
  380.  
  381.     if (self.spawnflags & PLAYER_ONLY)
  382.         if (other.classname != "player") return;
  383.  
  384. //dave changed to teleportweapons
  385.     if ((other.classname=="trigger_changelevel") |
  386.         (other.classname=="trap_shooter") |
  387.         (other.classname=="trap_spikeshooter") |
  388.         (other.classname=="trigger_secret") |
  389.         (other.classname=="door") |
  390.         (other.classname=="explo_box") |
  391.         (other.classname=="bubble") |
  392.         (other.classname=="path_corner") |
  393.         (other.classname=="plat") |
  394.         (other.classname=="train") |
  395.         (other.classname=="teledeath") |
  396.         (other.classname=="teledeath2") |
  397.         (other.classname=="DelayedUse") |
  398.         (other.classname=="info_player_start") |
  399.         (other.classname=="testplayerstart") |
  400.         (other.classname=="info_player_coop") |
  401.         (other.classname=="info_intermission") |
  402.         (other.classname=="info_player_deathmatch") |
  403.         (other.classname=="misc_teleporttrain") )
  404.     {
  405.     return;
  406.     }
  407.  
  408.     SUB_UseTargets ();
  409.  
  410. // put a tfog where the player was
  411.     spawn_tfog (other.origin);
  412.  
  413.     t = find (world, targetname, self.target);
  414.     if (!t)
  415.         objerror ("couldn't find target");
  416.         
  417. // spawn a tfog flash in front of the destination
  418.     makevectors (t.mangle);
  419.     org = t.origin + 32 * v_forward;
  420.  
  421.     spawn_tfog (org);
  422.     spawn_tdeath(t.origin, other);
  423.  
  424.     
  425. // move the player and lock him down for a little while
  426.     if (!other.health)
  427.     {
  428.         other.velocity=(v_forward*other.velocity_x)+(v_forward*other.velocity_y);
  429.         other.oldorigin=t.origin;
  430.         setorigin (other, t.origin);
  431.         return;
  432.     }
  433.  
  434.     setorigin (other, t.origin);
  435.  
  436.     other.angles = t.mangle;
  437.     if (other.classname == "player")
  438.     {
  439.         other.fixangle = 1;        // turn this way immediately
  440.         other.teleport_time = time + 0.7;
  441.         if (other.flags & FL_ONGROUND)
  442.             other.flags = other.flags - FL_ONGROUND;
  443.         other.velocity = v_forward * 300;
  444.     }
  445.     other.flags = other.flags - other.flags & FL_ONGROUND;
  446. };
  447.  
  448. /*QUAKED info_teleport_destination (.5 .5 .5) (-8 -8 -8) (8 8 32)
  449. This is the destination marker for a teleporter.  It should have a "targetname" field with the same value as a teleporter's "target" field.
  450. */
  451. void() info_teleport_destination =
  452. {
  453. // this does nothing, just serves as a target spot
  454.     self.mangle = self.angles;
  455.     self.angles = '0 0 0';
  456.     self.model = "";
  457.     self.origin = self.origin + '0 0 27';
  458.     if (!self.targetname)
  459.         objerror ("no targetname");
  460. };
  461.  
  462. void() teleport_use =
  463. {
  464.     self.nextthink = time + 0.2;
  465.     force_retouch = 2;        // make sure even still objects get hit
  466.     self.think = SUB_Null;
  467. };
  468.  
  469. /*QUAKED trigger_teleport (.5 .5 .5) ? PLAYER_ONLY SILENT
  470. Any object touching this will be transported to the corresponding info_teleport_destination entity. You must set the "target" field, and create an object with a "targetname" field that matches.
  471.  
  472. If the trigger_teleport has a targetname, it will only teleport entities when it has been fired.
  473. */
  474. void() trigger_teleport =
  475. {
  476.     local vector o;
  477.  
  478.     InitTrigger ();
  479.     self.touch = teleport_touch;
  480.     // find the destination 
  481.     if (!self.target)
  482.         objerror ("no target");
  483.     self.use = teleport_use;
  484.  
  485.     if (!(self.spawnflags & SILENT))
  486.     {
  487.         precache_sound ("ambience/hum1.wav");
  488.         o = (self.mins + self.maxs)*0.5;
  489.         ambientsound (o, "ambience/hum1.wav",0.5 , ATTN_STATIC);
  490.     }
  491. };
  492.  
  493.  
  494. /*
  495. ==============================================================================
  496.  
  497. trigger_setskill
  498.  
  499. ==============================================================================
  500. */
  501.  
  502. void() trigger_skill_touch =
  503. {
  504.     if (other.classname != "player")
  505.         return;
  506.         
  507.     cvar_set ("skill", self.message);
  508. };
  509.  
  510. /*QUAKED trigger_setskill (.5 .5 .5) ?
  511. sets skill level to the value of "message".
  512. Only used on start map.
  513. */
  514. void() trigger_setskill =
  515. {
  516.     InitTrigger ();
  517.     self.touch = trigger_skill_touch;
  518. };
  519.  
  520.  
  521. /*
  522. ==============================================================================
  523.  
  524. ONLY REGISTERED TRIGGERS
  525.  
  526. ==============================================================================
  527. */
  528.  
  529. void() trigger_onlyregistered_touch =
  530. {
  531.     if (other.classname != "player")
  532.         return;
  533.     if (self.attack_finished > time)
  534.         return;
  535.  
  536.     self.attack_finished = time + 2;
  537.     if (cvar("registered"))
  538.     {
  539.         self.message = "";
  540.         SUB_UseTargets ();
  541.         remove (self);
  542.     }
  543.     else
  544.     {
  545.         if (self.message != "")
  546.         {
  547.             centerprint (other, self.message);
  548.             sound (other, CHAN_BODY, "misc/talk.wav", 1, ATTN_NORM);
  549.         }
  550.     }
  551. };
  552.  
  553. /*QUAKED trigger_onlyregistered (.5 .5 .5) ?
  554. Only fires if playing the registered version, otherwise prints the message
  555. */
  556. void() trigger_onlyregistered =
  557. {
  558.     precache_sound ("misc/talk.wav");
  559.     InitTrigger ();
  560.     self.touch = trigger_onlyregistered_touch;
  561. };
  562.  
  563. //============================================================================
  564.  
  565. void() hurt_on =
  566. {
  567.     self.solid = SOLID_TRIGGER;
  568.     self.nextthink = -1;
  569. };
  570.  
  571. void() hurt_touch =
  572. {
  573.     if (other.takedamage)
  574.     {
  575.         self.solid = SOLID_NOT;
  576.         T_Damage (other, self, self, self.dmg);
  577.         self.think = hurt_on;
  578.         self.nextthink = time + 1;
  579.     }
  580.  
  581.     return;
  582. };
  583.  
  584. /*QUAKED trigger_hurt (.5 .5 .5) ?
  585. Any object touching this will be hurt
  586. set dmg to damage amount
  587. defalt dmg = 5
  588. */
  589. void() trigger_hurt =
  590. {
  591.     InitTrigger ();
  592.     self.touch = hurt_touch;
  593.     if (!self.dmg)
  594.         self.dmg = 5;
  595. };
  596.  
  597. //============================================================================
  598.  
  599. float PUSH_ONCE = 1;
  600.  
  601. void() trigger_push_touch =
  602. {
  603.     if (other.classname == "grenade")
  604.         other.velocity = self.speed * self.movedir * 10;
  605.     else if (other.health > 0)
  606.     {
  607.         other.velocity = self.speed * self.movedir * 10;
  608.         if (other.classname == "player")
  609.         {
  610.             if (other.fly_sound < time)
  611.             {
  612.                 other.fly_sound = time + 1.5;
  613.                 sound (other, CHAN_AUTO, "ambience/windfly.wav", 1, ATTN_NORM);
  614.             }
  615.         }
  616.     }
  617.     if (self.spawnflags & PUSH_ONCE)
  618.         remove(self);
  619. };
  620.  
  621.  
  622. /*QUAKED trigger_push (.5 .5 .5) ? PUSH_ONCE
  623. Pushes the player
  624. */
  625. void() trigger_push =
  626. {
  627.     InitTrigger ();
  628.     precache_sound ("ambience/windfly.wav");
  629.     self.touch = trigger_push_touch;
  630.     if (!self.speed)
  631.         self.speed = 1000;
  632. };
  633.  
  634. //============================================================================
  635.  
  636. void() trigger_monsterjump_touch =
  637. {
  638.     if ( other.flags & (FL_MONSTER | FL_FLY | FL_SWIM) != FL_MONSTER )
  639.         return;
  640.  
  641. // set XY even if not on ground, so the jump will clear lips
  642.     other.velocity_x = self.movedir_x * self.speed;
  643.     other.velocity_y = self.movedir_y * self.speed;
  644.     
  645.     if ( !(other.flags & FL_ONGROUND) )
  646.         return;
  647.     
  648.     other.flags = other.flags - FL_ONGROUND;
  649.  
  650.     other.velocity_z = self.height;
  651. };
  652.  
  653. /*QUAKED trigger_monsterjump (.5 .5 .5) ?
  654. Walking monsters that touch this will jump in the direction of the trigger's angle
  655. "speed" default to 200, the speed thrown forward
  656. "height" default to 200, the speed thrown upwards
  657. */
  658. void() trigger_monsterjump =
  659. {
  660.     if (!self.speed)
  661.         self.speed = 200;
  662.     if (!self.height)
  663.         self.height = 200;
  664.     if (self.angles == '0 0 0')
  665.         self.angles = '0 360 0';
  666.     InitTrigger ();
  667.     self.touch = trigger_monsterjump_touch;
  668. };
  669.  
  670.